import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { viteMockServe } from "vite-plugin-mock";

import { resolve } from "path";

function pathResolve(dir) {
  return resolve(process.cwd(), ".", dir);
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx({
      // options are passed on to @vue/babel-plugin-jsx
    }),
    viteMockServe({
      enable: true,
      mockPath: "./mock/",
    }),
  ],
  resolve: {
    alias: [
      {
        find: /@\//,
        replacement: pathResolve("src") + "/",
      },
    ],
  },
  server: {
    proxy: {
      "/axure": {
        target: "https://hdoxfy.axshare.com/",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/axure/, ""),
        // configure: (proxy, options) => {
        //   // proxy 是 'http-proxy' 的实例
        //   console.log(proxy, options);
        // },
        // bypass(req, res, options) {
        //   const key=req._parsedUrl.query.slice(4)
        //   console.log('xxxxxx',key)
        //   return 'http://www.baidu.com'
        // },
      },
    },
  },
});
